import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author Josiah Hotovec
 */
public class PlayerCount extends JFrame
{
    private static final int FRAME_WIDTH = 400;
    private static final int FRAME_HEIGHT = 100;

    int playerCount;

    JLabel instructions;
    JRadioButton twoPlayerButton;
    JRadioButton threePlayerButton;
    JRadioButton fourPlayerButton;

    ActionListener radioListener;

    public PlayerCount()
    {
        instructions = new JLabel("Please select the number of people playing:");
        add(instructions);

        class RadioListener implements ActionListener
        {
            public void actionPerformed(ActionEvent event)
            {
                if(twoPlayerButton.isSelected())
                {
                    playerCount = 2;
                }

                if(threePlayerButton.isSelected())
                {
                    playerCount = 3;
                }

                if(fourPlayerButton.isSelected())
                {
                    playerCount = 4;
                }
            }
        }

       radioListener = new RadioListener();

       createControlPanel();
       setSize(FRAME_WIDTH, FRAME_HEIGHT);
       setVisible(true);
    }

    public int getPlayerCount()
    {
        System.out.println(playerCount);
        return playerCount;
    }

    public void createControlPanel()
    {
        JPanel choices = createChoices();

        JPanel controlPanel = new JPanel();
        controlPanel.add(choices);

        add(controlPanel);
    }

    public JPanel createChoices()
    {

        twoPlayerButton = new JRadioButton("2 Players");
        twoPlayerButton.addActionListener(radioListener);

        threePlayerButton = new JRadioButton("3 Players");
        threePlayerButton.addActionListener(radioListener);

        fourPlayerButton = new JRadioButton("4 Players");
        fourPlayerButton.addActionListener(radioListener);

        ButtonGroup group = new ButtonGroup();

        group.add(twoPlayerButton);
        group.add(threePlayerButton);
        group.add(fourPlayerButton);

        JPanel panel = new JPanel();
        panel.add(twoPlayerButton);
        panel.add(threePlayerButton);
        panel.add(fourPlayerButton);
        
        return panel;
    }
}
